﻿using System;
using System.Threading.Tasks;
using ConsoleApp.Infrastructure.Rmq;
using ConsoleApp.Infrastructure.TaskFramework;
using ConsoleApp.Util;

namespace ConsoleApp.Job.TaskJob.队列消费
{
    public class 线上飞书消息消费任务 : TaskBase
    {
        public static string 线上飞书消息
        {
            get
            {
                return "Xigua.Shusi.FeiShuMsg";
            }
        }

        public override void Execute()
        {
			#region 入队
			for (int i = 0; i < 100; i++)
            {
                var feishudto = new FeiShuGroupMsg
                {
                    Content = $"测试{i}",
                    FeiShuGroupEnum = FeiShuGroupEnum.测试,
                };
                RmqQueueManager.Enqueue(feishudto, 线上飞书消息);
                ConsoleHelper.WriteInfoLine(feishudto.Content);
            }
            #endregion

            #region 队列信息

            var count=RmqQueueManager.GetQueueCount(线上飞书消息);
            ConsoleHelper.WriteInfoLine($"队列消息个数{count}");

            #endregion

            while (true)
            {
                new 线上飞书消息消费_RMQ(RmqQueueManager.Connect, 线上飞书消息).Start();
            }
        }

        public class 线上飞书消息消费_RMQ : ConsumerWorkerBase<FeiShuGroupMsg>
        {
            public 线上飞书消息消费_RMQ(RmqOption connection, string queueName):base(connection)
            {
                Console.Title = queueName;
                QueueName = queueName;
            }

            protected override bool HandleComingMessage(FeiShuGroupMsg feiShuGroupMsg)
            {
                FeiShuMsgHelper.SendGroupMsg(feiShuGroupMsg.FeiShuGroupEnum, feiShuGroupMsg.Content);
                feiShuGroupMsg.Content.WriteWarningLine();
                return true;
            }
        }
    }
}
